/**
 * $Id: CategoryListView.m 29 2008-01-17 07:10:07Z robertsaenz $
 */
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UIKit.h>

#import "MobileShoppingListApplication.h"
#import "CategoryListView.h"
#import "ItemListView.h"
#import "Category.h"

@implementation CategoryListView

- (id)initWithFrame:(struct CGRect)frame {
	self = [super initWithFrame:frame];
	viewType = CATLIST;
	viewTitle = @"Categories";
	UITableColumn *col = [[UITableColumn alloc] initWithTitle:@"Categories" identifier:@"categories" width:frame.size.width];
	[self enableRowDeletion: YES animated: YES];
	[self setRowHeight:45.0f];
	[self addTableColumn:col];
	[self setSeparatorStyle:1];
	[self setDataSource: self];
	[self setDelegate: self];

	delete = [UIImage applicationImageNamed:@"delete.png"];
	[self addCategory: @"Breads"];
	[self addCategory: @"Junk Food"];
	[self addCategory: @"Fruits"];
	[self addCategory: @"Meat"];
	[self addCategory: @"Dairy"];
	[self addCategory: @"Vegetables"];
	[self addCategory: @"Vegetables"];
	[self addCategory: @"Vegetables"];
	[self addCategory: @"Vegetables"];
	[self addCategory: @"Vegetables"];
	[self addCategory: @"Vegetables"];
	[self addCategory: @"Vegetables"];
	[self addCategory: @"Vegetables"];
	[self reloadData];

	return self;
}

- (void) addCategory: (NSString *) categoryName {
	UIImageAndTextTableCell* cell = [[UIImageAndTextTableCell alloc] init];
	NSMutableArray *items = [[NSMutableArray alloc] init];
	int i;
	for(i = 0; i < 5; ++i) {
		[items addObject: [NSString stringWithFormat: @"Item %d", i]];
	}
	[cell setShowDisclosure:YES];
	[cell setTitle: categoryName];
	Category *cat = [[Category alloc] initWithName: categoryName andItems: items];
	[cells addObject: cell];
	[cell release];
	[cat release];
}


// Data source methods
- (UITableCell*) table: (UITable*)table cellForRow: (int)row column: (int)col {
	UIImageAndTextTableCell *cell = [cells objectAtIndex: row];
	return cell;
}

// Delegate methods
- (void)tableRowSelected:(NSNotification *)notification {
	if(!itemView) {
		itemView = [[ItemListView alloc] initWithFrame: [self frame]];
	} else {
		[itemView clearTable];
	}

/*	NSMutableArray *items = [selectedCat getItems];
	int i;
	for(i = 0; i < items.count; ++i){
		[itemView addItem: [items objectAtIndex: i]];
	}
	[itemView reloadData];
	[sl loadView: itemView withTrans: 1 andPushItem: YES]; */
}

@end
